package com.zjjk.transfer.source.service.impl;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.zjjk.transfer.source.entity.SourceDataDictionary;
import com.zjjk.transfer.source.mapper.SourceDataDictionaryMapper;
import com.zjjk.transfer.source.service.SourceDataDictionaryService;
import com.zjjk.transfer.source.param.SourceDataDictionaryPageParam;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import io.geekidea.springbootplus.framework.common.service.impl.BaseServiceImpl;
import io.geekidea.springbootplus.framework.core.pagination.Paging;
import io.geekidea.springbootplus.framework.core.pagination.PageInfo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.transaction.annotation.Transactional;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * 数据字典 服务实现类
 *
 * @author xuziyang
 * @since 2021-03-26
 */
@Slf4j
@Service
@DS("source")
public class SourceDataDictionaryServiceImpl extends BaseServiceImpl<SourceDataDictionaryMapper, SourceDataDictionary> implements SourceDataDictionaryService {

    @Autowired
    private SourceDataDictionaryMapper sourceDataDictionaryMapper;

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean saveSourceDataDictionary(SourceDataDictionary sourceDataDictionary) throws Exception {
        return super.save(sourceDataDictionary);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean updateSourceDataDictionary(SourceDataDictionary sourceDataDictionary) throws Exception {
        return super.updateById(sourceDataDictionary);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean deleteSourceDataDictionary(Long id) throws Exception {
        return super.removeById(id);
    }

    @Override
    public Paging<SourceDataDictionary> getSourceDataDictionaryPageList(SourceDataDictionaryPageParam sourceDataDictionaryPageParam) throws Exception {
        Page<SourceDataDictionary> page = new PageInfo<>(sourceDataDictionaryPageParam, OrderItem.desc(getLambdaColumn(SourceDataDictionary::getCreateTime)));
        LambdaQueryWrapper<SourceDataDictionary> wrapper = new LambdaQueryWrapper<>();
        IPage<SourceDataDictionary> iPage = sourceDataDictionaryMapper.selectPage(page, wrapper);
        return new Paging<SourceDataDictionary>(iPage);
    }

}
